package com.adou.service.impl;

import com.adou.common.mapper.FlowMainFileMapper;
import com.adou.common.mapper.FlowTaskMapper;
import com.adou.common.model.FlowMainFile;
import com.adou.common.model.FlowTask;
import com.adou.service.FlowTaskService;
import com.adou.service.impl.base.BaseServiceImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class FlowTaskServiceImpl extends BaseServiceImp<FlowTask> implements FlowTaskService {

    @Autowired
    private FlowTaskMapper flowTaskMapper;

    @Autowired
    private FlowMainFileMapper flowMainFileMapper;

    @Override
    public int deleteBatch(List<FlowTask> o) {
        FlowTask flowTask = new FlowTask();
        FlowMainFile flowMainFile = new FlowMainFile();
        for (FlowTask f : o ) {
            flowTask.setId(f.getId());
            List<FlowTask> flowTaskList = flowTaskMapper.find(flowTask);
            if(flowTaskList.size()==1){
                flowMainFile.setIfmid(flowTaskList.get(0).getIfmid());
                List<FlowMainFile> flowMainFileList = flowMainFileMapper.find(flowMainFile);
                if(flowMainFileList.size()>0){
                    return -1;
                }
            }
        }
        return super.deleteBatch(o);
    }

    @Override
    public List<FlowTask> queryNodes(String id) {
        return flowTaskMapper.queryNodes(id);
    }
}
